<template>
	<view class="page_wrapper">
		<view class="form_block">
			<view class="form_row">
				<view class="row_name">功能名称：</view>
				<view class="row_val">
					<input class="dev_func_name" v-model="formData.funcName"  />
				</view>
			</view>
			<view class="form_row">
				<view class="row_name">功能说明：</view>
				<view class="row_val">
					<textarea class="remark" v-model="formData.remark"/>
				</view>
			</view>
		</view>
		<view class="btns_block">
			<view class="fcz_btn add_btn" @tap="addNewDevFunc()">
				创建我的功能需求
			</view>
		</view>
	</view>
</template>

<script>
	import {request} from '@/utils/request.js'
	export default {
		data() {
			return {
				formData: {
					funcName: '',
					remark: ''
				}
			}
		},
		methods: {
			addNewDevFunc() {
				if(!this.formData.funcName) {
					uni.showToast({ icon: 'none', title: '功能名称不能为空' })
					return false
				}
				if(!this.formData.remark) {
					uni.showToast({ icon: 'none', title: '功能说明不能为空' })
					return false
				}
				const data = JSON.parse(JSON.stringify(this.formData))
				data.funcType = 'math'
				uni.showLoading()
				request.postJson( 
					'/devFuncs', data
				).then(res => {
					uni.hideLoading()
					uni.showToast({ icon: 'none', title: '创建成功' })
					uni.navigateBack()
				}).catch(err => {
					uni.hideLoading()
					console.log(err)
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
  .page_wrapper{
		.form_block{
			flex: 1;
			padding: 0px 15px;
			overflow-y: scroll;
			.form_row{
				padding-top: 10px;
				padding-bottom: 10px;
				display: flex;
				.row_name{
					width: 100px;
					display: flex;
					align-items: center;
				}
				.row_val{
					flex: 1;
					.dev_func_name{
						text-align: center;
						height: 36px;
						border: 1px solid #c2c2c2;
						border-radius: 5px;
					}
					.remark{
						width: 100%;
						border: 1px solid #c2c2c2;
						border-radius: 5px;
						padding: 10px 0px;
					}
				}
			}
		}
		.btns_block{
			height: 60px;
			display: flex;
			justify-content: center;
			align-items: center;
			.fcz_btn{
				flex: 0.8;
				height: 40px;
				color: white;
				background-color: #67C23A;
				display: flex;
				justify-content: center;
				align-items: center;
				border-radius: 5px;
			}
			.add_btn{
				background-color: #67C23A;
			}
		}
	}
</style>
